package com.yuejian_06.yuejian_06.adapter;

import android.content.Context;
import android.net.Uri;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.MediaController;
import android.widget.VideoView;

import com.yuejian_06.yuejian_06.R;
import com.yuejian_06.yuejian_06.bean.ClubVideoBean;
import com.yuejian_06.yuejian_06.fragment.Constants;
import com.yuejian_06.yuejian_06.fragment.Constants_l;

import java.util.List;

/**
 * Created by songedwin on 2017/10/17.
 */

public class ClubVideoAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List mDataList;
    private LayoutInflater mLayoutInflater;
    public ClubVideoAdapter(Context mContext, List mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.club_video_cardview, parent, false);
        return new ClubVideoAdapter.ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final ClubVideoBean entity = (ClubVideoBean) mDataList.get(position);
        if (null == entity)
            return;
        ClubVideoAdapter.ViewHolder viewHolder = (ClubVideoAdapter.ViewHolder) holder;

        String internetUrl = Constants.SSS+"yuejian/Public/clubVideo/"+entity.getVideo();
        if(!entity.getVideo().isEmpty())
        {
            viewHolder.club_video.setVideoURI(Uri.parse(internetUrl));
            MediaController controller =new MediaController(mContext);
            viewHolder.club_video.setMediaController(controller);
            controller.setMediaPlayer(viewHolder.club_video);

        }
        else
        {}
//        holder.itemView.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Intent intent=new Intent(mContext, ClubInfoActivity.class);
//                intent.putExtra("club_id",entity.getClub_id());
//                mContext.startActivity(intent);
//            }
//        });

    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
       VideoView club_video;

        public ViewHolder(View itemView) {
            super(itemView);
           club_video=(VideoView) itemView.findViewById(R.id.club_video_videoView);
        }
    }
}
